package com.icez.data.di

import android.content.Context
import androidx.room.Room
import com.icez.data.AppDatabase
import com.icez.data.dao.CategoriesDao
import com.icez.data.dao.EpisodesDao
import com.icez.data.dao.PodcastCategoryEntryDao
import com.icez.data.dao.PodcastFollowedEntryDao
import com.icez.data.dao.PodcastsDao
import com.icez.data.dao.TransactionRunner
import com.rometools.rome.io.SyndFeedInput
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseDiModule {

    @Provides
    @Singleton
    fun provideDatabase(@ApplicationContext context: Context): AppDatabase = Room.databaseBuilder(context,AppDatabase::class.java,"data.db")
        .fallbackToDestructiveMigration()
        .build()

    @Provides
    @Singleton
    fun provideCategoriesDao(database: AppDatabase): CategoriesDao = database.categoriesDao()

    @Provides
    @Singleton
    fun providePodcastCategoryEntryDao(database: AppDatabase): PodcastCategoryEntryDao = database.podcastCategoryEntryDao()

    @Provides
    @Singleton
    fun providePodcastsDao(database: AppDatabase): PodcastsDao = database.podcastsDao()

    @Provides
    @Singleton
    fun provideEpisodesDao(database: AppDatabase): EpisodesDao = database.episodesDao()

    @Provides
    @Singleton
    fun providePodcastFollowedEntryDao(database: AppDatabase): PodcastFollowedEntryDao = database.podcastFollowedEntryDao()

    @Provides
    @Singleton
    fun provideTransactionRunner(database: AppDatabase): TransactionRunner = database.transactionRunnerDao()



}